const state = {
  tabsRouter: [],
};

const getters = {
  tabsRouter: (state: any) => state.tabsRouter,
};

const mutations = {
  addTabsRouter(state: any, route: any) {
    let flag = false;
    state.tabsRouter.forEach((element: any) => {
      if (element.path === route.path) {
        flag = true;
      }
    });
    if (!flag) {
      state.tabsRouter.push(route);
    }
  },
  setTabsRouter(state: any, tabsRouter: []) {
    state.tabsRouter = tabsRouter;
  },
};

const actions = {
  /**
   * 增加标签页路由
   * @param context
   * @param route
   */
  addTabsRouter(context: any, route: any) {
    context.commit("addTabsRouter", route);
  },
  /**
   * 设置标签页路由列表
   * @param context
   * @param tabsRouter
   */
  setTabsRouter(context: any, tabsRouter: []) {
    context.commit("setTabsRouter", tabsRouter);
  },
};

export default { state, getters, mutations, actions };
